package com.application.lucky.adapter;


import android.view.View;

import com.application.lucky.R;
import com.application.lucky.bean.jsonBean.RechargeGroup;
import com.application.lucky.bean.jsonBean.RechargeItem;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

import static com.application.lucky.bean.jsonBean.RechargeGroup.TYPE_LEVEL_0;
import static com.application.lucky.bean.jsonBean.RechargeGroup.TYPE_LEVEL_1;

public class RechargeAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {


    public RechargeAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_recharge_lv0);
        addItemType(TYPE_LEVEL_1, R.layout.item_recharge_lv1);
    }

    @Override
    protected void convert(BaseViewHolder helper,  MultiItemEntity bean) {
        final int position = helper.getAdapterPosition();
        switch (helper.getItemViewType()) {
            case TYPE_LEVEL_0:
                RechargeGroup item = (RechargeGroup) bean;
                final RechargeGroup finalItem = item;
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (finalItem.isExpanded()) {
                            collapse(position);
                        } else {
                            expand(position);
                        }
                    }});
                helper.setImageResource(R.id.iv_recharge_icon, item.iconRes)
                        .setText(R.id.tv_recharge_title, item.title);
                break;
            case TYPE_LEVEL_1:
                RechargeItem item1 = (RechargeItem) bean;
                helper.setText(R.id.tv_recharge_title1, "通道")
                        .setText(R.id.tv_recharge_title2, item1.content);
                break;
        }
    }

}
